<?php

class Antz_Form_Components_Radiogroup extends Antz_Form_Component
{
    protected $opts = array();

    public function __construct($name, $selected='')
    {
        $this->name = $name;
        $this->addClass('radioGroup');
        $this->selected = $selected;
    }

    public function add($val, $label='&nbsp;', $id='')
    {
        $key = count($this->opts);
        if($id=='')$id = 'opt'.$key;
        $obj = Antz::newObject('Antz_Form_Components_Radio');
        $obj->name = $this->name;
        $obj->setId($id);
        $obj->value = $val;
        $obj->label = $label;
        $this->opts[$key] = $obj;
        return $obj;
    }

    public function render()
    {
        $html = array();
        foreach($this->opts as $k=>$opt){
            $html[] = $opt->render($this->selected);
        };
        $returnString = '<div class="checkboxGroup">'.implode("\n", $html).'</div>';
        if($this->wrap) $returnString = $this->wrap($returnString);
        return $returnString;
    }
}
